#!python
# -*- coding: utf-8 -*-

from google.appengine.api import images
from google.appengine.api import users
from google.appengine.ext import db

from django.http import Http404
from django.utils.translation import ugettext as _

from common import redirect, respond
from models import Album, Picture
from django.conf import settings

import cgi

_params = {'menu_album': True,
           'title': _("tags"),}

def home(request):
    tags = []
    for pic in Picture.all().order('-submitted_date').fetch(100):
        for tag in pic.tags:
            try:
                tags.index(tag)
            except:
                tags.append(tag)
    params = _params.copy()
    params.update({ 'tags': tags })
    return respond('tag_home.html', params)

def detail(request, tag):
    pictures = Picture.all().filter('tags =', tag)
    params = _params.copy()
    params.update({ 'pictures': pictures,
                    'tag': tag,
                    'title': tag, })

    return respond('tag_detail.html', params)
